<template>
<el-form-item label="农产品分类">
    <el-cascader v-model="landComputedCode" :props="{ checkStrictly: true }" filterable :options="landProduct" @change="handleChange">
    </el-cascader>
</el-form-item>
</template>

<script>
import {
    convertKey
} from "@/library";
export default {
    props: {
        landCode: {
            type: [Number, String, Array],
        }
    },
    data() {
        return {
            datalandCode:this.landCode,
            originProduct:[],
            originlandProduct: [],
            landProduct: [],
            landProductCode: []
        }
    },
    computed: {
        landComputedCode: {
            get() {
                return this.datalandCode
            },
            set(val){
                this.datalandCode = val
            }
        }
    },
    created() {
        this.getlandProductList()
    },
    methods: {
        getlandProductList() {
            this.$common.getlandProduct()
                .then((res) => {
                    this.$store.commit('setlandProduct', res.data.list)
                    this.landProduct = convertKey(res.data.list, {
                        productTypeName: "label",
                        productTypeCode: "value",
                    });
                });

        },
        handleChange(value) {
            this.landProductCode = value[value.length - 1]
            this.$emit("on-change", value[value.length - 1])
        },
    },
}
</script>
